package com.niiwoo.civet.trade.service.dubbo.configure;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.trade.dto.response.OcrPortraitAuthConfigResponseDTO;
import com.niiwoo.civet.trade.dto.response.ProjectIntroduceDTO;
import com.niiwoo.civet.trade.enums.TradeConfigEnum;
import com.niiwoo.civet.trade.service.configure.TradeConfigDubboService;
import com.niiwoo.civet.trade.service.local.configure.TradeConfigLocalService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service(version = "1.0.0")
public class TradeConfigServiceDubboImpl implements TradeConfigDubboService {

    @Autowired
    private TradeConfigLocalService tradeConfigLocalService;


    @Override
    public Map<String, String> selectTradeConfigByEmuns(List<TradeConfigEnum> enumList) {
        Map<String, String> map =tradeConfigLocalService.selectTradeConfigByEmuns(enumList);
        return map;
    }

    @Override
    public OcrPortraitAuthConfigResponseDTO queryOcrPortraitConfig() {
        OcrPortraitAuthConfigResponseDTO dto =new OcrPortraitAuthConfigResponseDTO();
        List<TradeConfigEnum> enumList =new ArrayList<TradeConfigEnum>();
        enumList.add(TradeConfigEnum.OCRSCANIDCARDSWITCH);
        enumList.add(TradeConfigEnum.OCRSCANIDCARDDEVICE);
        enumList.add(TradeConfigEnum.OCRSCANBANKCARDSWITCH);
        enumList.add(TradeConfigEnum.OCRSCANBANKCARDDEVICE);
        enumList.add(TradeConfigEnum.PORTRAITAUTHSWITCH);
        enumList.add(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTBLINK);
        enumList.add(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTOPENMOUTH);
        enumList.add(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTNODHEAD);
        enumList.add(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTSHAKEHEAD);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSSYNTHETICFACETHRESHOLD);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSMASKTHRESHOLD);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSSCREENREPLAYTHRESHOLD);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSIDIMAGETHRESHOLDMIN);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSIDIMAGETHRESHOLDMAX);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSLIVEIMAGETHRESHOLDMIN);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSLIVEIMAGETHRESHOLDMAX);
        enumList.add(TradeConfigEnum.PORTRAITAUTHFACEPLUSDEVICE);
        Map<String, String> map =tradeConfigLocalService.selectTradeConfigByEmuns(enumList);
        if (map != null){
            dto.setOcrScanBankCardSwitch(map.get(TradeConfigEnum.OCRSCANBANKCARDSWITCH.getConfigKey()));
            dto.setOcrScanBankCardDevice(map.get(TradeConfigEnum.OCRSCANBANKCARDDEVICE.getConfigKey()));
            dto.setOcrScanIdCardSwitch(map.get(TradeConfigEnum.OCRSCANIDCARDSWITCH.getConfigKey()));
            dto.setOcrScanIdCardDevice(map.get(TradeConfigEnum.OCRSCANIDCARDDEVICE.getConfigKey()));
            dto.setPortraitAuthSwitch(map.get(TradeConfigEnum.PORTRAITAUTHSWITCH.getConfigKey()));
            dto.setPortraitAuthActionFacePlusDetectBlink(map.get(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTBLINK.getConfigKey()));
            dto.setPortraitAuthActionFacePlusDetectOpenMouth(map.get(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTOPENMOUTH.getConfigKey()));
            dto.setPortraitAuthActionFacePlusDetectNodHead(map.get(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTNODHEAD.getConfigKey()));
            dto.setPortraitAuthActionFacePlusDetectShakeHead(map.get(TradeConfigEnum.PORTRAITAUTHACTIONFACEPLUSDETECTSHAKEHEAD.getConfigKey()));
            dto.setPortraitAuthFacePlusSyntheticFaceThreshold(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSSYNTHETICFACETHRESHOLD.getConfigKey()));
            dto.setPortraitAuthFacePlusMaskThreshold(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSMASKTHRESHOLD.getConfigKey()));
            dto.setPortraitAuthFacePlusScreenReplayThreshold(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSSCREENREPLAYTHRESHOLD.getConfigKey()));
            dto.setPortraitAuthFacePlusIdImageThresholdMin(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSIDIMAGETHRESHOLDMIN.getConfigKey()));
            dto.setPortraitAuthFacePlusIdImageThresholdMax(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSIDIMAGETHRESHOLDMAX.getConfigKey()));
            dto.setPortraitAuthFacePlusLiveImageThresholdMin(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSLIVEIMAGETHRESHOLDMIN.getConfigKey()));
            dto.setPortraitAuthFacePlusLiveImageThresholdMax(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSLIVEIMAGETHRESHOLDMAX.getConfigKey()));
            dto.setPortraitAuthFacePlusDevice(map.get(TradeConfigEnum.PORTRAITAUTHFACEPLUSDEVICE.getConfigKey()));
        }
        return dto;
    }

    @Override
    public OcrPortraitAuthConfigResponseDTO queryR360PortraitConfig() {
        OcrPortraitAuthConfigResponseDTO dto =new OcrPortraitAuthConfigResponseDTO();
        List<TradeConfigEnum> enumList =new ArrayList<TradeConfigEnum>();
        enumList.add(TradeConfigEnum.RONG360BLINKIMAGETHRESHOLDMIN);
        enumList.add(TradeConfigEnum.RONG360BLINKIMAGETHRESHOLDMAX);
        enumList.add(TradeConfigEnum.RONG360IDIMAGETHRESHOLDMIN);
        enumList.add(TradeConfigEnum.RONG360IDIMAGETHRESHOLDMAX);
        Map<String, String> map = tradeConfigLocalService.selectTradeConfigByEmuns(enumList);
        if (map != null) {
            dto.setPortraitAuthFacePlusLiveImageThresholdMin(map.get(TradeConfigEnum.RONG360BLINKIMAGETHRESHOLDMIN.getConfigKey()));
            dto.setPortraitAuthFacePlusLiveImageThresholdMax(map.get(TradeConfigEnum.RONG360BLINKIMAGETHRESHOLDMAX.getConfigKey()));
            dto.setPortraitAuthFacePlusIdImageThresholdMin(map.get(TradeConfigEnum.RONG360IDIMAGETHRESHOLDMIN.getConfigKey()));
            dto.setPortraitAuthFacePlusIdImageThresholdMax(map.get(TradeConfigEnum.RONG360IDIMAGETHRESHOLDMAX.getConfigKey()));

            //融360不需配置，这里设置默认值
            dto.setPortraitAuthFacePlusSyntheticFaceThreshold("0.5");
            dto.setPortraitAuthFacePlusMaskThreshold("0.5");
            dto.setPortraitAuthFacePlusScreenReplayThreshold("0.5");
        }
        return dto;
    }

    @Override
    public String selectDeadlineByAmount(BigDecimal amount){
        return tradeConfigLocalService.selectDeadlineByAmount(amount);
    }

    @Override
    public Byte rateConfig(int loanTerm, Byte configType){
        return tradeConfigLocalService.rateConfig(loanTerm, configType);
    }

    @Override
    public String selectTradeConfigByEmun(TradeConfigEnum configEnum){
        return tradeConfigLocalService.selectTradeConfigByEmun(configEnum);
    }

    @Override
    public ProjectIntroduceDTO getProjectIntroduce() {
        ProjectIntroduceDTO dto = new ProjectIntroduceDTO();

        List<TradeConfigEnum> enumList = new ArrayList<TradeConfigEnum>();
        enumList.add(TradeConfigEnum.PERSONAL_PROJECT_INTRODUCE_IMG_URL);
        enumList.add(TradeConfigEnum.COMPANY_PROJECT_INTRODUCE_IMG_URL);

        Map<String, String> map = tradeConfigLocalService.selectTradeConfigByEmuns(enumList);
        if (map != null) {
            dto.setPersonalProjectIntroduceImgUrl(map.get(TradeConfigEnum.PERSONAL_PROJECT_INTRODUCE_IMG_URL.getConfigKey()));
            dto.setCompanyProjectIntroduceImgUrl(map.get(TradeConfigEnum.COMPANY_PROJECT_INTRODUCE_IMG_URL.getConfigKey()));
        }

        return dto;
    }
}
